﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>前端JSONP跨域调用</title>
    <script type="text/javascript" src="/js/jquery-1.8.1.js"></script>
    <script type="text/javascript" src="/js/json2.js"></script>
    <style type="text/css">
        * {
            font-family: Consolas, '微软雅黑', '宋体';
            font-size: 14px;
        }
    </style>
</head>
<body>
    <p>
        <button id="btnTest">开始测试</button>
    </p>
    <hr />
    <p><b>测试结果：</b></p>
    <div id="divOutput"></div>

    <script type="text/javascript">
        $(function () {
            $("#btnTest").click(function () {
                var urls = [];                
                urls.push({ type: "POST", url: "http://www.fish-web-demo.com/user/Login.aspx", data: { rightNo: 11, username: "fish", ignoreRedirect: true }, async: false });
                urls.push({ type: "POST", url: "http://www.fish-web-demo.com/api/ns/TestCors/Test2.aspx", data: { input: "Fish Li" }, async: true });
                urls.push({ type: "POST", url: "http://www.fish-web-demo.com/api/ns/TestCors/Add.aspx", data: { a: 3, b: 2 }, async: true });

                $.each(urls, function (i, item) {
                    $.ajax({
                        type: item.type,
                        url: item.url,
                        data: item.data,
                        dataType: "jsonp",
                        //jsonp: "jsonpcallback",
                        success: function (result) {
                            var html = "<div>URL: " + item.url + "<br />Result: " + JSON.stringify(result) + "<br /><br /></div>";
                            $("#divOutput").append(html);
                        }
                    });
                });
            });
        });
    </script>
</body>
</html>
